package cn.maszy.action.investment;


import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;

import net.sourceforge.stripes.action.SessionScope;
import cn.maszy.common.BaseAction;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.model.investment.B_T_Ufp_Work;
import cn.maszy.service.investment.B_T_Ufp_WorkService;

@SessionScope
public class WorkAction extends BaseAction<B_T_Ufp_Work> {
	/**
	 * 
	 */
	
	private static final long serialVersionUID = 5665168993634171907L;
	private String strattime;
	private String endtime;
	private int strutrs;
	private int str;
	private int dateString;
	@Autowired
	private B_T_Ufp_WorkService b_T_Ufp_WorkService;
	private B_T_Ufp_Work b_T_Ufp_Work;

	/*********************class set/get****************************/
	
	public String getEndtime() {
		return endtime;
	}
	
	

	public int getStr() {
		return str;
	}



	public void setStr(int str) {
		this.str = str;
	}



	public int getDateString() {
		return dateString;
	}



	public void setDateString(int dateString) {
		this.dateString = dateString;
	}



	public int getStrutrs() {
		return strutrs;
	}

	public void setStrutrs(int strutrs) {
		this.strutrs = strutrs;
	}

	public void setEndtime(String endtime) {
		this.endtime = endtime;
	}
	public String getStrattime() {
		return strattime;
	}
	public void setStrattime(String strattime) {
		this.strattime = strattime;
	}
	
	public B_T_Ufp_Work getB_T_Ufp_Work() {
		return b_T_Ufp_Work;
	}
	public void setB_T_Ufp_Work(B_T_Ufp_Work b_T_Ufp_Work) {
		this.b_T_Ufp_Work = b_T_Ufp_Work;
	}
	/*******************STRUTS ACTION METHOD*************************/
	/**
	 * 考勤列表
	 * @return
	 * @throws Exception
	 */
	public String workList() throws Exception {
		pager = new Pager<B_T_Ufp_Work>(pageNum, numPerPage,orderField,orderDirection);
		pager= b_T_Ufp_WorkService.selectList(b_T_Ufp_Work,pager,strattime,endtime);
		//控制上下班签到按钮
		b_T_Ufp_Work = b_T_Ufp_WorkService.selectwork(SessionFactory.getSessionUserId());
		if(b_T_Ufp_Work.getWorketime()==null){
					str=1;
		}else{
					str=2;
		}
		if(b_T_Ufp_Work.getWorkstime()==null){
					dateString=1;
		}else{
					dateString=2;
		}
		return SUCCESS;
	}
	/**
	 * 上班签到
	 */
	public String punch() throws Exception {
		int i = b_T_Ufp_WorkService.update(b_T_Ufp_Work);
		Map<String, Object> sessionMap = ActionContext.getContext().getSession();
		sessionMap.put("dateString", "已打卡");
		if (i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "WorkList","", "forward", "investment/WorkList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 下班签到
	 * @return
	 * @throws Exception
	 */
	public String punchnext() throws Exception {
		int i = b_T_Ufp_WorkService.updatenext(b_T_Ufp_Work);
//		ssionMap.put("qiandao", "正常上班");
		if (i>0)
		return ajaxForwardSuccess(getText("msg.operation.success"), "WorkList","", "forward", "investment/WorkList");
		return ajaxForwardError(getText("msg.operation.failure"));
	}
	/**
	 * 考勤统计
	 * @return
	 * @throws Exception
	 */
	public String statisticsList() throws Exception{
		pager = new Pager<B_T_Ufp_Work>(pageNum, numPerPage,orderField,orderDirection);
		pager=  b_T_Ufp_WorkService.selectstatisticsList(b_T_Ufp_Work,pager,strattime,endtime);
		return SUCCESS;
	}
}
